package com.cleaningcloud.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cleaningcloud.erp.domain.dto.ErpWareReportingDto;
import com.cleaningcloud.erp.domain.vo.ErpWareReportingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.erp.domain.ErpWareReporting;
import com.cleaningcloud.erp.service.IErpWareReportingService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 报损单Controller
 * 
 * @author cleaningcloud
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/ErpWareReporting")
public class ErpWareReportingController extends BaseController
{
    @Autowired
    private IErpWareReportingService erpWareReportingService;

    /**
     * 查询报损单列表
     */
    @RequiresPermissions("erp:ErpWareReporting:list")
    @GetMapping("/list")
    public TableDataInfo list(ErpWareReporting erpWareReporting)
    {
        startPage();
        List<ErpWareReportingVo> list = erpWareReportingService.selectErpWareReportingList(erpWareReporting);
        return getDataTable(list);
    }

    /**
     * 导出报损单列表
     */
    @RequiresPermissions("erp:ErpWareReporting:export")
    @Log(title = "报损单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpWareReporting erpWareReporting)
    {
        List<ErpWareReportingVo> list = erpWareReportingService.selectErpWareReportingList(erpWareReporting);
        ExcelUtil<ErpWareReportingVo> util = new ExcelUtil<ErpWareReportingVo>(ErpWareReportingVo.class);
        util.exportExcel(response, list, "报损单数据");
    }

    /**
     * 获取报损单详细信息
     */
    @RequiresPermissions("erp:ErpWareReporting:query")
    @GetMapping(value = "/{wareReportingId}")
    public AjaxResult getInfo(@PathVariable("wareReportingId") Long wareReportingId)
    {
        return success(erpWareReportingService.selectErpWareReportingByWareReportingId(wareReportingId));
    }

    /**
     * 新增报损单
     */
    @RequiresPermissions("erp:ErpWareReporting:add")
    @Log(title = "报损单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpWareReportingDto erpWareReporting)
    {
        return toAjax(erpWareReportingService.insertErpWareReporting(erpWareReporting));
    }

    /**
     * 修改报损单
     */
    @RequiresPermissions("erp:ErpWareReporting:edit")
    @Log(title = "报损单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpWareReportingDto erpWareReporting)
    {
        return toAjax(erpWareReportingService.updateErpWareReporting(erpWareReporting));
    }

    /**
     * 审核调拨
     */
    @RequiresPermissions("erp:ErpWareReporting:audit")
    @Log(title = "审核报损单", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody ErpWareReporting erpWareReporting)
    {
        return toAjax(erpWareReportingService.auditErpWareReporting(erpWareReporting));
    }

    /**
     * 删除报损单
     */
    @RequiresPermissions("erp:ErpWareReporting:remove")
    @Log(title = "报损单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wareReportingIds}")
    public AjaxResult remove(@PathVariable Long[] wareReportingIds)
    {
        return toAjax(erpWareReportingService.deleteErpWareReportingByWareReportingIds(wareReportingIds));
    }
}
